package com.sccc.actions;
import com.sccc.biz.IUserManeger;
import com.sccc.bizImpl.UserManeger;
import com.sccc.entity.User;
import com.sccc.entity.User;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAndRigister extends ActionSupport{
	
	ActionContext ctx = ActionContext.getContext();
	    private int id;
		private String username;
		private String sex;
		private String passwd;
		private String job;
		private String email;
		private String qm;
		String sucStr = "alert('恭喜你，会员注册成功');";
	
	
	public String getSucStr() {
			return sucStr;
		}

		public void setSucStr(String sucStr) {
			this.sucStr = sucStr;
		}

	public int getId() {
			return id;
		}

		public void setId(int id) {
			this.id = id;
		}

		public String getUsername() {
			return username;
		}

		public void setUsername(String username) {
			this.username = username;
		}

		public String getSex() {
			return sex;
		}

		public void setSex(String sex) {
			this.sex = sex;
		}

		public String getPasswd() {
			return passwd;
		}

		public void setPasswd(String passwd) {
			this.passwd = passwd;
		}

		public String getJob() {
			return job;
		}

		public void setJob(String job) {
			this.job = job;
		}

		public String getEmail() {
			return email;
		}

		public void setEmail(String email) {
			this.email = email;
		}

		public String getQm() {
			return qm;
		}

		public void setQm(String qm) {
			this.qm = qm;
		}
		
		
	public String login()throws Exception{
		
		String user = getUsername();//页面传进来的账号
		String pwd = getPasswd();//页面传进来的账号
		User myuser = new User(user,pwd);
		
		IUserManeger Umaeger = new UserManeger();//接口new实现类
		
		if(Umaeger.Userlogin(myuser)){

	
		   ctx.getSession().put("userId", UserManeger.showuserinfo.getId());    
       	   ctx.getSession().put("userName", UserManeger.showuserinfo.getUsername());
       	   ctx.getSession().put("userSex", UserManeger.showuserinfo.getSex());
       	   ctx.getSession().put("userJob", UserManeger.showuserinfo.getJob());
       	   ctx.getSession().put("userEmail", UserManeger.showuserinfo.getEmail());
           ctx.getSession().put("userQm", UserManeger.showuserinfo.getQm());
     
		       return SUCCESS;
		}else{
			   return ERROR;
		}	
	}
	
	public String goLoginAndReg()throws Exception{
		return "goLoginAndReg";
	}
	
	public String regist()throws Exception{
		
		String user = getUsername();
		String sex = getSex();
		String pass = getPasswd();
		String job = getJob();
		String email = getEmail();
		User reginfo = new User(user,sex,pass,job,email);
		IUserManeger reg = new UserManeger();//接口new实现类
		if (reg.Userregister(reginfo)){
			HttpServletRequest request = ServletActionContext.getRequest();  
			request.setAttribute("regSuc", sucStr);
			 //ctx.getSession().put("regSuc", sucStr);
			return "regsuc";
		}else{
			return ERROR;
		}
		
	}	
	
	

}
